﻿using System;
using System.ComponentModel;
using System.Windows.Forms;

using Argos.Scheduling;
using System.Configuration;
using System.Drawing;

namespace Argos.Windows.Forms
{
	public partial class TimeSlotEditorDialog: Form
	{
		public TimeSlotEditorDialog()
		{
			InitializeComponent();

			this.Size = Settings.Default.FormSize;
		}

		public TimeSlot SelectedSlot
		{
			get
			{
				if (this.Editor.SelectedObject is TimeSlot)
				{
					return (TimeSlot)this.Editor.SelectedObject;
				}
				return new TimeSlot();
			}
			set { this.Editor.SelectedObject = value; }
		}



		protected override void OnClosing(CancelEventArgs e)
		{
			base.OnClosing(e);

			if (!e.Cancel && this.WindowState == FormWindowState.Normal)
			{
				Settings.Default.FormSize = this.Size;
				Settings.Default.Save();
			}
		}

		private void OK_Click(object sender, EventArgs e)
		{
			this.DialogResult = DialogResult.OK;
			this.Close();
		}


		private class Settings : ApplicationSettingsBase
		{

			public static Settings Default = (Settings)ApplicationSettingsBase.Synchronized(new Settings());

			[UserScopedSetting]
			[DefaultSettingValue("400, 300")]
			public Size FormSize
			{
				get { return (Size)this["FormSize"]; }
				set { this["FormSize"] = value; }
			}

		}

	}
}
